﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_AddStep_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_AddStep_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_AddStep_V2]
    @FlowID int,
    @StepName nvarchar(300),
    @StepRemark nvarchar(max),
    @RightToFinish bit,
    @FlowRule int,
    @PassNum int = 0,
    @LocalAlert bit = 0,
    @BaseHour int = 0,
    @CycTimes int = 0,
    @Period int = 0
/*
===================================================

功能:    添加步骤
参数:
    @FlowID int            ：    流程ID
    @StepName nvarchar(300)    ：    步骤名称
    @StepRemark ntext        ：    步骤介绍
    @RightToFinish bit        ：    能否结束
    @FlowRule int            ：    流转规则
    @PassNum int = 0        ：    会签规则
    @LocalAlert bit =0        ：    固定提醒
    @BaseHour int = 0        ：    基本时间
    @CycTimes int = 0        ：    循环次数
    @Period int =0            ：    周期

===================================================
*/
AS
BEGIN
SET NOCOUNT ON;

DECLARE @StepID INT;

SELECT @StepID = ISNULL(MAX(Step_ID), 0) + 1 FROM dbo.UDS_Flow_Step WHERE flow_id = @FlowID;

INSERT INTO dbo.UDS_Flow_Step (Step_name, Step_Remark, RightToFinish, Flow_Rule, PassNum, Flow_id, Step_ID, LocalAlert, BaseHour, CycTimes, Period)
    VALUES (
        @StepName, @StepRemark, @RightToFinish, @FlowRule, @PassNum,
        @FlowID, @StepID,
        @LocalAlert, @BaseHour, @CycTimes, @Period
    );

IF @@ERROR = 0
    RETURN @StepID;

RETURN -1;

END
GO